import { defineStore } from 'pinia'

export const tabDataStore = defineStore('tabDataStore', {
  state: () => {
    return {
      list: [{ title: '邮件', key: 'view', closable: false, component: 'EmailComponent' }],
      activeKey: 'view'
    }
  },
  actions: {
    writeEmail() {
      if (!this.list.find(item => item.key === 'write')) {
        this.list.push({ title: '写邮件', key: 'write', closable: true, component: 'WriteEmailComponent' })
      }
      this.activeKey = 'write'
    },
    removeTab(targetKey) {
      const index = this.list.findIndex(item => item.key === targetKey)
      this.list.splice(index, 1)
      this.activeKey = this.list[this.list.length - 1]['key']
    }
  }
})
